package com.mad.game.view;

import java.awt.Graphics;
import java.awt.image.BufferStrategy;

import com.mad.game.backend.GameDemo;
import com.mad.game.controller.MainWndKeyController;
import com.mad.game.view.graphics.Renderer;

public class MainWnd extends DefaultWnd {

	private static final long serialVersionUID = 1L;
	
	public MainWnd() {
		super(GameDemo.TITLE+" - Game", ViewManager.MAIN_WND_WIDTH, ViewManager.MAIN_WND_HEIGHT); 
	}

	@Override
	protected void init() {
		super.init();
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		this.setResizable(false);
		this.addKeyListener(new MainWndKeyController(this));
		this.makeVisible(); 
	}
	
	@Override
	public void paint(Graphics g) {
		BufferStrategy bs = this.getBufferStrategy();
		if(bs == null){
			this.createBufferStrategy(2); 
			this.requestFocus();
			return ; 
		}
		g = bs.getDrawGraphics();
		super.paint(g);
		Renderer.startRenderingPipeline(g, this.getWidth(), this.getHeight());
		bs.show(); 
	}
	
}
